package test.org.dei;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import org.dei.perla.context.CDT;
import org.dei.perla.context.Context;
import org.dei.perla.context.Dimension;
import org.dei.perla.context.DimensionStructure;
import org.dei.perla.context.NotFoundException;
import org.dei.perla.context.Value;
import org.dei.perla.context.ValueOnBased;
import org.dei.perla.context.ValueWhenBased;
import org.dei.perla.parser.expressions.Constant;
import org.dei.perla.parser.expressions.ConstantCastException;
import org.dei.perla.parser.expressions.ConstantInteger;
import org.dei.perla.parser.expressions.ConstantString;
import org.dei.perla.parser.util.PairValue;

public class RelativeSensorsTEST {

	/**
	 * @param args
	 * @throws NotFoundException 
	 * @throws ConstantCastException 
	 */
	public static void main(String[] args) throws NotFoundException, ConstantCastException {
		CDT cdt = CDT.getDefault();
		DimensionStructure dim1 = new Dimension("dim1","root",null);
		cdt.addDimensionToCDT(dim1);
	    Value val11= new ValueWhenBased("val11", "dim1","temp>4");
		Value val12= new ValueOnBased("val12", "dim1","viticoltore()");
		val11.setDimension(dim1);
		val12.setDimension(dim1);
		Set<Constant<?>> set1 = new HashSet<Constant<?>>() ;
		ConstantInteger i1= new ConstantInteger(1);
		ConstantInteger i2= new ConstantInteger(2);
		ConstantInteger i3= new ConstantInteger(3);
		ConstantInteger i4= new ConstantInteger(4);
		ConstantInteger i5= new ConstantInteger(5);
		
		set1.add(i1);
		set1.add(i2);
		set1.add(i3);
		val11.setValueSensors(set1);
		
		
		dim1.getValues().add(val11);
		dim1.getValues().add(val12);
		
		DimensionStructure dim2 = new Dimension("dim2", "root",null);
		cdt.addDimensionToCDT(dim2);
		Value val21= new ValueWhenBased("val21", "dim2","hum>10");
		Value val22= new ValueOnBased("val22", "dim2","vigna()");
		val21.setDimension(dim2);
		val22.setDimension(dim2);
		dim2.getValues().add(val21);
		dim2.getValues().add(val22);
		Set<Constant<?>> set2 = new HashSet<Constant<?>>() ;
		set2.add(i1);
		set2.add(i2);
		set2.add(i3);
		set2.add(i4);
		val22.setValueSensors(set2);
		
		
		PairValue<ConstantString,ConstantString> pair = new PairValue<ConstantString,ConstantString>();
		pair.setFirst(new ConstantString("dim1"));
		pair.setSecond(new ConstantString("val11"));
		ArrayList<PairValue<ConstantString,ConstantString>> dimvalue= new ArrayList<PairValue<ConstantString,ConstantString>>();
		dimvalue.add(pair);
		
		
		pair = new PairValue<ConstantString,ConstantString>();
		pair.setFirst(new ConstantString("dim2"));
		pair.setSecond(new ConstantString("val22"));
		dimvalue.add(pair);
		
		
			Context contesto = new Context ("prova",null,dimvalue,null);
			
			contesto.calcolaRelativeSensors();
			Iterator<Constant<?>> t=contesto.getRelativeSensors().iterator();
			for( int i=0;i<contesto.getRelativeSensors().size();i++){
			System.out.println(t.next().getValueInt());
			
			}
			}

}
